home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kiconviewsearchline.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  4.6 KB  |  180 lines

  1. /*
  2.    This file is part of the KDE libraries
  3.    Copyright (c) 2004 Gustavo Sverzut Barbieri <gsbarbieri@users.sourceforge.net>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License version 2 as published by the Free Software Foundation.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19.  
  20. #ifndef KICONVIEWSEARCHLINE_H
  21. #define KICONVIEWSEARCHLINE_H
  22.  
  23. #include <klineedit.h>
  24. #include <qvaluelist.h>
  25.  
  26. class QIconView;
  27. class QIconViewItem;
  28.  
  29. /**
  30.  * This class makes it easy to add a search line for filtering the items in a
  31.  * iconview based on a simple text search.
  32.  *
  33.  * No changes to the application other than instantiating this class with an
  34.  * appropriate QIconView should be needed.
  35.  *
  36.  * @since 3.3
  37.  */
  38. class KDEUI_EXPORT KIconViewSearchLine : public KLineEdit
  39. {
  40.   Q_OBJECT
  41.  
  42. public:
  43.  
  44.   /**
  45.    * Constructs a KIconViewSearchLine with \a iconView being the QIconView to
  46.    * be filtered.
  47.    *
  48.    * If \a iconView is null then the widget will be disabled until a iconview
  49.    * is set with setIconView().
  50.    */
  51.   KIconViewSearchLine( QWidget *parent = 0,
  52.                QIconView *iconView = 0,
  53.                const char *name = 0 );
  54.  
  55.   /**
  56.    * Constructs a KIconViewSearchLine without any QIconView to filter. The
  57.    * QIconView object has to be set later with setIconView().
  58.    */
  59.   KIconViewSearchLine( QWidget *parent, const char *name );
  60.  
  61.   /**
  62.    * Destroys the KIconViewSearchLine.
  63.    */
  64.   virtual ~KIconViewSearchLine();
  65.  
  66.   /**
  67.    * Returns true if the search is case sensitive.  This defaults to false.
  68.    *
  69.    * @see setCaseSensitive()
  70.    */
  71.   bool caseSensitive() const;
  72.  
  73.   /**
  74.    * Returns the iconview that is currently filtered by the search.
  75.    *
  76.    * @see setIconView()
  77.    */
  78.   QIconView *iconView() const;
  79.  
  80.  
  81. public slots:
  82.   /**
  83.    * Updates search to only make visible the items that match \a s.  If
  84.    * \a s is null then the line edit's text will be used.
  85.    */
  86.   virtual void updateSearch( const QString &s = QString::null );
  87.  
  88.   /**
  89.    * Make the search case sensitive or case insensitive.
  90.    *
  91.    * @see caseSenstive()
  92.    */
  93.   void setCaseSensitive( bool cs );
  94.  
  95.   /**
  96.    * Sets the QIconView that is filtered by this search line.  If \a lv is null
  97.    * then the widget will be disabled.
  98.    *
  99.    * @see iconView()
  100.    */
  101.   void setIconView( QIconView *iv );
  102.  
  103.  
  104.   /**
  105.    * Clear line edit and empty hiddenItems, returning elements to iconView.
  106.    */
  107.   void clear();
  108.  
  109.  
  110. protected:
  111.   /**
  112.    * Returns true if \a item matches the search \a s.  This will be evaluated
  113.    * based on the value of caseSensitive().  This can be overridden in
  114.    * subclasses to implement more complicated matching schemes.
  115.    */
  116.   virtual bool itemMatches( const QIconViewItem *item,
  117.                 const QString &s ) const;
  118.  
  119.  
  120.   /**
  121.    * Do initialization common to both constructors.
  122.    */
  123.   void init( QIconView *iconView = 0 );
  124.  
  125.   /**
  126.    * Hide item.
  127.    */
  128.   void hideItem( QIconViewItem *item );
  129.  
  130.   /**
  131.    * Show item.
  132.    *
  133.    * Just unhide it, doesn't necessary show it on screen, for that use
  134.    * iconView->ensureItemVisible()
  135.    */
  136.   void showItem( QIconViewItem *item );
  137.  
  138.  
  139. protected slots:
  140.   /**
  141.    * When keys are pressed a new search string is created and a timer is
  142.    * activated.  The most recent search is activated when this timer runs out
  143.    * if another key has not yet been pressed.
  144.    *
  145.    * This method makes @param s the most recent search and starts the
  146.    * timer.
  147.    *
  148.    * Together with activateSearch() this makes it such that searches are not
  149.    * started until there is a short break in the users typing.
  150.    *
  151.    * @see activateSearch()
  152.    */
  153.   void queueSearch( const QString &s );
  154.  
  155.   /**
  156.    * When the timer started with queueSearch() expires this slot is called.
  157.    * If there has been another timer started then this slot does nothing.
  158.    * However if there are no other pending searches this starts the icon view
  159.    * search.
  160.    *
  161.    * @see queueSearch()
  162.    */
  163.   void activateSearch();
  164.  
  165.  
  166. private slots:
  167.   /**
  168.    * Take action need when iconView is deleted.
  169.    */
  170.   void iconViewDeleted();
  171.  
  172.  
  173. private:
  174.   class KIconViewSearchLinePrivate;
  175.   KIconViewSearchLinePrivate *d;
  176. };
  177.  
  178.  
  179. #endif /* KICONVIEWSEARCHLINE_H */
  180.